﻿using Desktop.Controls;
using Desktop.Dialogs;
using Desktop.Interfaces;
using Desktop.Library;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StoryWriter
{
    /// <summary>
    /// Interaction logic for Dashboard.xaml
    /// </summary>
    public partial class Dashboard : ActivityBase
    {
        #region Constructors

        public Dashboard(IWorkspace parent)
            : base(parent)
        {
            InitializeComponent();
        }

        #endregion

        #region Event Handlers

        private void ListView_Loaded(object sender, RoutedEventArgs e)
        {
            (sender as ListView).DataContext = SessionManager.Instance.StoryList;
        }

        private void New_Click(object sender, RoutedEventArgs e)
        {
            Parent.OpenActivity(new StoryEditor(Parent));
        }

        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            Story story = storyListView.SelectedItem as Story;
            if (story == null)
            {
                return;
            }

            Parent.OpenActivity(new StoryEditor(Parent, story));
        }

        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            Story story = storyListView.SelectedItem as Story;
            if (story == null)
            {
                return;
            }

            SessionManager.Instance.StoryList.Remove(story);
        }

        private void Import_Click(object sender, RoutedEventArgs e)
        {
            string feedUrl = BloggerImport.GetFeedUrl();
            if (string.IsNullOrEmpty(feedUrl))
            {
                return;
            }
            SessionManager.Instance.StoryList.Add(new Story(feedUrl));
        }

        #endregion
    }
}